package com.molichuxing.gateway.bff.payment.services.impl;

import java.util.ArrayList;
import java.util.Map;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.molichuxing.framework.dto.Paged;
import com.molichuxing.gateway.bff.payment.convertor.Convert;
import com.molichuxing.gateway.bff.payment.entity.response.AlipayLogVo;
import com.molichuxing.gateway.bff.payment.entity.response.OfflineBookyueVo;
import com.molichuxing.gateway.bff.payment.entity.response.WechatpayLogVo;
import com.molichuxing.gateway.bff.payment.services.EscrowLogBffService;
import com.molichuxing.services.infrastructure.dto.response.EscrowLogDto;
import com.molichuxing.services.infrastructure.dto.response.OfflineBookyueDto;
import com.molichuxing.services.infrastructure.service.EscrowLogService;
import com.molichuxing.services.infrastructure.service.OfflineBookyueService;
import com.molichuxing.services.property.EscrowLogTypeEnum;
import com.molichuxing.services.property.PaymentChannelEnum;

/**
 * 第三方支付日志bff
 *
 * @Author zoumingyu
 * @Date 2020年04月01日
 */
@Service("escrowLogBffService")
public class EscrowLogBffServiceImpl implements EscrowLogBffService {
    private static final Logger logger = LoggerFactory.getLogger(EscrowLogBffServiceImpl.class);

    @Resource
    private EscrowLogService escrowLogService;
    
    @Resource
    private OfflineBookyueService offlineBookyueService;

    /**
     * 获取微信支付日志
     *
     * @param params
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public Paged<WechatpayLogVo> getWechatpayLog(Map<String, Object> params, int pageNum, int pageSize) throws Exception {
        Paged<WechatpayLogVo> result = new Paged<>(new ArrayList<>(), 0, pageSize);
        params.put("channel", PaymentChannelEnum.WXPAY.getValue());
        params.put("type", EscrowLogTypeEnum.ORDER_PAY.getValue());

        Paged<EscrowLogDto> escrowLogDtoPage = escrowLogService.getPage(params, pageNum, pageSize);
        result.setTotal(escrowLogDtoPage.getTotal()).setList(Convert.toWechatpayLogVo(escrowLogDtoPage.getList()));

        return result;
    }

    /**
     * 获取支付宝支付日志
     *
     * @param params
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public Paged<AlipayLogVo> getAlipayLog(Map<String, Object> params, int pageNum, int pageSize) throws Exception {
        Paged<AlipayLogVo> result = new Paged<>(new ArrayList<>(), 0, pageSize);
        params.put("channel", PaymentChannelEnum.ALIPAY.getValue());
        params.put("type", EscrowLogTypeEnum.ORDER_PAY.getValue());

        Paged<EscrowLogDto> escrowLogDtoPage = escrowLogService.getPage(params, pageNum, pageSize);
        result.setTotal(escrowLogDtoPage.getTotal()).setList(Convert.toAlipayLogVo(escrowLogDtoPage.getList()));

        return result;
    }
    
    /**
     * 获取 费用记录 线下支付 （安鹏）
     * @param orderCode
     * @return
     */
    @Override
    public OfflineBookyueVo getOfflineBookyue(Long orderCode) {
    	OfflineBookyueDto dto = offlineBookyueService.getByOrderCode(orderCode);
    	return Convert.toOfflineBookyueVo(dto);
    }
}
